<template>
	<view>
		<!-- #ifdef APP-PLUS || MP-WEIXIN -->
		<u-swipe-action>
			<u-swipe-action-item :options="options2" @click="getActionEvent" :name="item.id" v-for="item in list"
				:key="item.id">
				<u-cell :title="item.content" :value="item.admin.nickname
				" :label="item.createtime" center></u-cell>
			</u-swipe-action-item>
		</u-swipe-action>
		<!-- #endif -->
		<!-- #ifdef H5 -->
		<u-cell :title="item.content" :value="item.admin.nickname" v-for="item in list" :key="item.id">
			<text slot="label">
				<view style="color:#909193">{{item.createtime}}</view>
				<view class="vaan">
					<u-button type="primary" text="编辑" :customStyle="annuStyle" @click="getActionEvent({index:0,name:item.id})"></u-button>
					<u-button type="error" text="删除" :customStyle="annuStyle1"
						@click="getActionEvent({index:1,name:item.id})"></u-button>
				</view>
			</text>
		</u-cell>
		<!-- #endif -->
		<!-- 确认框 -->
		<u-modal :show="show" :content='content' showCancelButton @cancel="show = false"
			@confirm="confirmDel"></u-modal>
		<u-button type="success" text="添加回访记录" color="#19BC9C" :customStyle="btnStyle" @click="goAddPages"></u-button>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				btnStyle: {
					width: '100%',
					position: 'fixed',
					bottom: '0px'
				},
				options2: [{
					text: '编辑',
					style: {
						backgroundColor: '#3c9cff'
					}
				}, {
					text: '删除',
					style: {
						backgroundColor: '#f56c6c'
					}
				}],
				list: [],
				LoginUser: {},
				annuStyle: {
					width: '10%',
					transform: 'translateX(-200%)',
				},
				annuStyle1: {
					width: '10%',
					transform: 'translateX(-577%)'
				},
				btnStyle: {
					width: '100%',
					position: 'fixed',
					bottom: '0px'
				},
				show: false,
				content: '确认是否删除回访记录名称？',
				id:0
			}
		},
		onReady() {
			this.$u.auth.check();
			this.LoginUser = uni.getStorageSync('LoginUser') ? uni.getStorageSync('LoginUser') : {}
			this.getVistData()
		},
		methods: {
			async getVistData() {
				let result = await this.$u.api.manage.vistIndex({
					adminid: this.LoginUser.id
				})
				if (result.code == 1) {
					this.list = result.data
				}
			},
			goAddPages() {
				uni.navigateTo({
					url: '/pages/manage/visit/add'
				})
			},
			getActionEvent(val) {
				if (val.index == 0) {
					uni.navigateTo({
						url: '/pages/manage/visit/edit?id=' + val.name
					})
				} else {
					this.show = true
					this.id = val.name
				}
			},
			async confirmDel() {
				this.show = false
				let result = await this.$u.api.manage.vistDel({
					id: this.id
				})
				if (result.code == 1) {
					this.getVistData()
					this.$refs.uToast.show({
						type: 'success',
						message: result.msg
					})
				} else {
					this.$refs.uToast.show({
						type: 'error',
						message: result.msg
					})
				}
			}
		}
	}
</script>

<style lang="scss">
	
		.vaan{
			display: flex;
			
		}
</style>